
function GalerieSejourController($scope, $rootScope, UploadManager, Sejour, filterFilter) {
	$scope.scSejour = null;/*instance objet Sejour*/
	$scope.images = null;/*liste des dispo pour le séjour*/
	$scope.alerts = [];/*pile des alertes*/
	$scope.scSejour = new Sejour();
	$scope.addButton = "Ajouter";
	$scope.updateButton = "Modifier";
	
    $scope.files = [];
    $scope.percentage = 0;


	var idSejour = parseInt(document.querySelector("#id").value);

	var addAlert = function(typeAlert, msgAlert) {
		$scope.alerts.push({type: typeAlert, msg: msgAlert});
	};

	$scope.closeAlert = function(index) {
		$scope.alerts.splice(index, 1);
	};

	var resetForm = function () {
		UploadManager.clear();
		$scope.files = [];
    }

    $scope.upload = function () {
        UploadManager.upload();
        $scope.files = [];
    };

    $rootScope.$on('fileAdded', function (e, call) {
        $scope.files.push(call);
        $scope.$apply();
    });

    $rootScope.$on('uploadProgress', function (e, call) {
        $scope.percentage = call;
        $scope.$apply();
    });

    $rootScope.$on('uploadDone', function (e) {
        RetourneListingImages();
    });


	$scope.cancel = function() {
		resetForm();
	}

	/* retourne toutes les disponibilités du séjour */
	var RetourneListingImages = function () {
		$scope.scSejour.retourneGalerieImagesSejour( idSejour ).then(function(e){
			$scope.images = e.data;
		});	
	}
	
	$scope.deleteImage = function(datas) {
		$scope.scSejour.supprimerUneImageSejour(datas.idImage).then(function(e) {
    		RetourneListingImages();
    		addAlert('success', "L'image "+ datas.image +" a \351t\351 supprim\351e de la galerie avec succ\350s.");
		});
	}

	RetourneListingImages();

	resetForm();
}
